package com.wlyuan.open.controller;

import com.wlyuan.open.api.IOpenApiCompanyService;
import com.wlyuan.open.controller.resolver.OpenApiCompanyFilterResolver;
import com.wlyuan.open.dto.api.*;
import com.wlyuan.open.vo.OpenApiCompanyDetailVO;
import com.wlyuan.open.vo.OpenApiCompanyVO;
import com.wlyuan.utils.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author lijing
 */
@Slf4j
@Api(tags = "公司api管理")
@Validated
@RequestMapping("/company")
@RestController
public class OpenApiCompanyController extends BaseController {
    @DubboReference(check = false)
    private IOpenApiCompanyService openApiCompanyService;
    private final OpenApiCompanyFilterResolver filterResolver;

    public OpenApiCompanyController(OpenApiCompanyFilterResolver filterResolver) {
        this.filterResolver = filterResolver;
    }

    @ApiOperation(value = "申请api")
    @PostMapping("")
    public void create(@Valid @RequestBody OpenApiCompanyCreationDTO creationDTO) {
        creationDTO.setAppId(getAppId());
        openApiCompanyService.create(creationDTO);
    }

    @ApiOperation(value = "api接口管理")
    @PostMapping("/client/list")
    public Page<OpenApiCompanyVO> clientSearch(@RequestBody OpenApiCompanyDTO filter) {
        filter.setAppId(getAppId());
        return openApiCompanyService.list(filter);
    }

    @PostMapping("/search")
    public Page<OpenApiCompanyDetailVO> search(@RequestBody OpenApiCompanyFilterDTO filter) {
        filterResolver.resolver(filter);
        return openApiCompanyService.search(filter);
    }

    @PutMapping("/enable")
    public void enable(@Valid @RequestBody OpenApiCompanyEnableDTO enable) {
        openApiCompanyService.enable(enable);
    }

    @PutMapping("/disable")
    public void disable(@Valid @RequestBody OpenApiCompanyDisableDTO disable) {
        openApiCompanyService.disable(disable);
    }

    @PutMapping("/examine")
    public void enable(@Valid @RequestBody OpenApiCompanyExamineDTO examine) {
        openApiCompanyService.examine(examine);
    }

    @PutMapping("/reject")
    public void disable(@Valid @RequestBody OpenApiCompanyRejectDTO reject) {
        openApiCompanyService.reject(reject);
    }
}
